layui.define(["table", "form", "admin"], function (exports) {
    var $ = layui.$,
        table = layui.table,
        admin = layui.admin;

    table.render({
        elem: "#LAY-live-manage",
        url: config.live_getlives,
        editTrigger: 'dblclick',
        cols: [[
            {
                field: "",
                title: "序号",
                width: 60,
                fixed: "left",
                templet: function (d) {
                    return d.LAY_INDEX;
                },
            },
            {
                field: "",
                width: 100,
                title: "主播ID",
                fixed: "left",
                templet: function (d) {
                    return d.anchor ? d.anchor.id : '';
                },
            },
            {
                field: "",
                title: "主播昵称",
                width: 100,
                templet: function (d) {
                    return d.anchor ? d.anchor.nick_name : '';
                },
            },

            {
                field: "",
                title: "直播类型",
                width: 100,
                templet: function (d) {
                    return d.category ? d.category.title : '';
                },
            },
            {field: "title", title: "直播标题", width: 200},
            {
                field: "",
                title: "直播封面",
                width: 100,
                templet: function (d) {
                    return '<img style="display: inline-block; width: auto; height: 100%;" layadmin-event="photosPreview" src="' + d.thumb + '"  value="' + d.thumb + '">'
                },
            },
            {
                field: "", title: "关联比赛ID", width: 150, templet: function (d) {
                    return d.matchid > 0 ? d.matchid : "";
                },
            },
            {
                field: "",
                title: "直播赛事",
                width: 120,
                templet: function (d) {
                    return d.matches ? d.matches.comp + '（' + d.matches.home + ' VS ' + d.matches.away + '）' : '';
                },
            },

            {field: "start_stamp", title: "开播时间", width: 180},
            {
                field: "",
                title: "直播状态",
                width: 100,
                templet: function (d) {
                    switch (d.status) {
                        case 0:
                            return "主播暂时离开";
                        case 1:
                            return "直播中";
                        case 2:
                            return "未开播";
                        default:
                            return "";
                    }
                },
            },

            {
                field: 'pull_flv_url', title: '拉流地址', minWidth: 150, templet: function (d) {
                    return '<a href="javascript:;" data-clipboard-text="" class="font-primary" title="点击复制" lay-event="copyCoverUhdUrl">' + d.pull_flv_url + '</a>';
                }
            },

        ],
        ],
        page: true,
        limit: 20,
        height: "full-140",
        text: {
            none: '暂无数据'
        },
        even: true,
    });

    // 直播历史
    table.render({
        elem: '#LAY-livehistory-manage'
        , url: config.live_get_history
        , cols: [[
            {field: 'id', title: 'ID', width: 70, fixed: "left"}
            , {field: 'anchorid', title: '主播ID', width: 100, fixed: "left"}
            , {
                field: '', title: '主播昵称', width: 120, templet: function (d) {
                    return d.anchor ? d.anchor.nick_name : '';
                }
            }
            , {field: 'start_stamp_str', title: '开播时间', width: 180}
            , {field: 'end_stamp_str', title: '结束时间', width: 180}
            , {field: 'live_minute', title: '直播时长', width: 180}
            , {field: 'liveid', title: '直播编号', width: 140}
            , {field: 'title', title: '直播标题', minWidth: 150}
            , {
                field: '', title: '直播分类', width: 100, templet: function (d) {
                    return d.category ? d.category.title : '';
                }
            }
            , {
                field: '', title: '联赛名称', width: 120, templet: function (d) {
                    return d.matches ? d.matches.comp : '';
                }
            }
            , {
                field: '', title: '主队名称', width: 120, templet: function (d) {
                    return d.matches ? d.matches.home : '';
                }
            }
            , {
                field: '', title: '客队名称', width: 120, templet: function (d) {
                    return d.matches ? d.matches.away : '';
                }
            }
        ]]
        , page: true
        , limit: 20
        , height: 'full-140'
        , text: '对不起，加载出现异常！'
        , even: true
    });

    //查看照片
    admin.events.photosPreview = function (othis) {
        let urls = othis.attr("value");
        let urlarr = new Array();
        $.each(urls.split(","), function (i, val) {
            urlarr.push({src: val});
        });
        layer.photos({
            photos: {
                title: "查看照片", //相册标题
                data: urlarr,
            },
            shade: 0.01,
            closeBtn: 1,
            anim: 5,
        });
    };

    exports("guild/live", {});
});
